package com.lwc.controller;

import com.lwc.bean.EnterpriseCategory;
import com.lwc.bean.EnterpriseTree;
import com.lwc.common.bean.ResultBean;
import com.lwc.common.controller.BaseController;
import com.lwc.service.EnterpriseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.math3.analysis.function.Rint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@Api(tags = "企业类别")
public class EnterpriseCategoryController extends BaseController {
    @Autowired
    EnterpriseCategoryService enterpriseCategoryService;

    @PostMapping("/enterpriseCategoryService")
    @ApiOperation("新增类别")
    public ResultBean save(@RequestBody EnterpriseCategory enterpriseCategory){
          enterpriseCategoryService.save(enterpriseCategory);
        return success("新增类别成功");
    }


    @DeleteMapping("/enterpriseCategoryService/delete")
    @ApiOperation("删除类别")
    public  ResultBean delete( int id){
        int rs=enterpriseCategoryService.delete(id);
        return rs==1?success("删除成功"):fail("删除失败");
    }


    @ApiImplicitParams({
            @ApiImplicitParam(required = true,name = "id",value = "类别id",dataTypeClass = Integer.class),
            @ApiImplicitParam(required = true,name = "name",value = "类别姓名",dataTypeClass = String.class),
            @ApiImplicitParam(required = true,name = "status",value = "类别状态",dataTypeClass = Integer.class)
    })
    @ApiOperation("更改类别")
    @PutMapping("/enterpriseCategoryService/update")
    public  ResultBean update( int id,  String name,  int status ){
      int rs=  enterpriseCategoryService.update(id,name,status);
        return  rs==1?success("更新成功"):fail("更新失败");
    }


    @ApiOperation("查询类别数")
    @GetMapping("/enterpriseCategoryService/query")
    public  ResultBean query(){

    List <EnterpriseCategory>list= enterpriseCategoryService.querylist();
if (list.isEmpty()){
    return fail("查询失败内容为空");
}
        return success("查询成功",list);
    }

    @ApiOperation("类别列表")
    @GetMapping("enterpriseCategoryService/select")
    public  ResultBean query1(){
        List<EnterpriseCategory>list=enterpriseCategoryService.query();
        return success("查询成功",list);
    }

    @ApiOperation("类别数")
    @GetMapping("enterprise/tree")
    public  ResultBean tree(){
List<EnterpriseTree>list=enterpriseCategoryService.tree();
      return   success("类别数查询成功",list);
    }

}
